<?php
/*=============================================================================
|| ##################################################################
||	phpFoX Konsort
|| ##################################################################
||	
||	Copyright		: (C) 2005-2007 PHPFOX Limited a Reality Fox Creation
||	Contact			: info@phpfox.com
||
||	- phpFoX and all of its source code and files are protected by Copyright Laws. 
||
||	- The license for phpFoX permits you to install this software on a single domain (.com, .org, .net, etc.). 
||
||	- You may also not remove this copyright screen which shows the copyright information and credits for phpFoX (RealityFOX Creations). 
||
||	- phpFoX Konsort is NOT a FREE software - http://www.phpfox.com/license/
||
|| ##################################################################
=============================================================================*/

/* $File: ./include/modules/Account/classes/PhpFox_ComponentFriends.class.php, $Author:  $ */



/** Display short list of friends
 * 
 * Parameters:
 *  1. oUser (mandatory) - user account object
 *  2. bIsTop (optional) - true - show only top friends
 * 
 * @package module.account
 * @version $Id: PhpFox_ComponentFriends.class.php 416 2008-03-28 07:20:51Z phpfoxsv $
 *   
 */
class PhpFox_Mod_Account_ComponentFriends extends BaseComponent
{

    /** Processing method
     */
	function process()
	{
	    $oAcc = $this->getParam('oUser');
	    assert(null != $oAcc);
	    
		$oTpl = &$this->_oModule->getTemplate();
		$oSrvFriends = $this->_oModule->getService('Friends');
		/* @var $oSrvFriends PhpFox_Mod_Account_ServiceFriends */
		$bIsTop = $this->getParam('bIsTop', false);
		
		$iNumShow = $this->getParam('iNumShow', 6);		
		// list($aFriends,$iCnt) = $oSrvFriends->getTopFriendList($oAcc, 0, $iNumShow, '', $bIsTop);
		$iCnt = $oAcc->aData['c_friends'];
		$aFriends = $this->oDatabase->getRows("
			SELECT u.user
			FROM ". App::getT('friends') ." AS f
				LEFT JOIN " . App::getT('user') . " AS u
					ON f.friend = u.user
			WHERE f.user = '{$oAcc->aData['user']}'
			ORDER BY f.top DESC, f.top_order ASC, f.time DESC LIMIT 0, ". ($oAcc->aData['total_friends'] ? $oAcc->aData['total_friends'] : App::getParam('public.top.friends')) ."
		");
		
		$sTemplate = $this->getParam('sTemplate', 'Friends');
		$oTpl->assign(array(
			'iNumFriends' => $iCnt,			
			'iRowSize'    => $this->getParam('iRowSize', 3),
			'aFriends'    => $aFriends,
			'aCurrUser'   => $oAcc->aData,
		    'bIsTop'      => $bIsTop,
		    'bHasFriends' => $iCnt,
			'sUserPicUrl' => App::getParam('user.pic.url'),
		));
		
		$srcHtml = $oTpl->fetch($sTemplate.'.html');
		return $srcHtml;
	}

}
?>